package com.newjiabo.ski.service.impl;

import java.util.List;

import com.newjiabo.common.utils.DateUtils;
import com.newjiabo.common.utils.SecurityUtils;
import com.newjiabo.ski.domain.SkiMealSnowRel;
import com.newjiabo.ski.mapper.SkiMealSnowRelMapper;
import com.newjiabo.ski.service.ISkiMealSnowRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 套餐-雪地关联Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-18
 */
@Service
public class SkiMealSnowRelServiceImpl implements ISkiMealSnowRelService {
    @Resource
    private SkiMealSnowRelMapper skiMealSnowRelMapper;

    /**
     * 查询套餐-雪地关联
     *
     * @param snowFieldId 套餐-雪地关联主键
     * @return 套餐-雪地关联
     */
    @Override
    public List<SkiMealSnowRel> selectSkiMealSnowRelBySnowFieldId(String snowFieldId) {
        return skiMealSnowRelMapper.selectSkiMealSnowRelBySnowFieldId(snowFieldId);
    }

    /**
     * 查询套餐-雪地关联列表
     *
     * @param skiMealSnowRel 套餐-雪地关联
     * @return 套餐-雪地关联
     */
    @Override
    public List<SkiMealSnowRel> selectSkiMealSnowRelList(SkiMealSnowRel skiMealSnowRel) {
        return skiMealSnowRelMapper.selectSkiMealSnowRelList(skiMealSnowRel);
    }

    /**
     * 新增套餐-雪地关联
     *
     * @param skiMealSnowRel 套餐-雪地关联
     * @return 结果
     */
    @Override
    public int insertSkiMealSnowRel(SkiMealSnowRel skiMealSnowRel) {
        skiMealSnowRel.setCreateTime(DateUtils.getNowDate());
        return skiMealSnowRelMapper.insertSkiMealSnowRel(skiMealSnowRel);
    }

    /**
     * 修改套餐-雪地关联
     *
     * @param skiMealSnowRel 套餐-雪地关联
     * @return 结果
     */
    @Override
    public int updateSkiMealSnowRel(SkiMealSnowRel skiMealSnowRel) {
        return skiMealSnowRelMapper.updateSkiMealSnowRel(skiMealSnowRel);
    }

    /**
     * 批量删除套餐-雪地关联
     *
     * @param snowFieldIds 需要删除的套餐-雪地关联主键
     * @return 结果
     */
    @Override
    public int deleteSkiMealSnowRelBySnowFieldIds(String[] snowFieldIds) {
        return skiMealSnowRelMapper.deleteSkiMealSnowRelBySnowFieldIds(snowFieldIds);
    }

    /**
     * 删除套餐-雪地关联信息
     *
     * @param snowFieldId 套餐-雪地关联主键
     * @return 结果
     */
    @Override
    public int deleteSkiMealSnowRelBySnowFieldId(String snowFieldId) {
        return skiMealSnowRelMapper.deleteSkiMealSnowRelBySnowFieldId(snowFieldId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean saveBatch(List<SkiMealSnowRel> relList) {
        // 首先要删除该雪场下所有的
        String snowFieldId = relList.get(0).getSnowFieldId();
        this.deleteSkiMealSnowRelBySnowFieldId(snowFieldId);
        for (SkiMealSnowRel skiMealSnowRel : relList) {
            skiMealSnowRel.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        }
        skiMealSnowRelMapper.saveBatch(relList);
        return true;
    }

    @Override
    public int deleteSkiMealSnowRelBySetMealIds(String[] ids) {
        return skiMealSnowRelMapper.deleteSkiMealSnowRelBySetMealIds(ids);
    }
}
